package Bio::Rambam::Proteomics::Formats::Rawdata;

use Moose;
use namespace::autoclean;
use Moose::Util::TypeConstraints;
with 'Bio::Rambam::Proteomics::Tools::FileGeneration';
extends 'Bio::Rambam::Proteomics::Formats::File';
use Bio::Rambam::Proteomics qw($MZML_SCHEMA_FILE $MZML_SCHEMA_FILE_NOINDX);
use Data::Dumper;
use XML::LibXML;
use XML::LibXML::XPathContext;
use Try::Tiny;
enum 	'file_types', [qw(indexed_mzml not_indexed_mzml)];
has 	'file_type'	=>	(is=>'ro',	isa=>'file_types',	writer => '_set_file_type'	);
has 	'version'	=>	(is=>'ro',	isa=>'Str', 		writer => '_set_version',	predicate => 'has_version');

sub BUILD {
	my ($self)=shift;
	$self->_set_version('1.1.1');	##### Parche para que vaya rapido
	return;
	
	my $parser = XML::LibXML->new();
	
	my $file=$self->file;
	my $mzml_noindex_valid;
	my $mzml_index_valid;
	my $mzmlschema_index	= XML::LibXML::Schema->new( location => $MZML_SCHEMA_FILE);
	my $mzmlschema_noindex 	= XML::LibXML::Schema->new( location => $MZML_SCHEMA_FILE_NOINDX);
	my $doc = $parser->parse_file($file);
	try{
		$mzmlschema_index->validate( $doc );		
		$mzml_index_valid=1;
	}
	catch{$mzml_index_valid=0;};
	
	try{
		$mzmlschema_noindex->validate( $doc );		
		$mzml_noindex_valid=1;
	}
	catch{$mzml_noindex_valid=0;};
	
	($self->_set_version('1.1.0') and $self->_set_file_type('not_indexed_mzml')) if 	$mzml_index_valid and		$mzml_noindex_valid;
	($self->_set_version('1.1.1') and $self->_set_file_type('indexed_mzml')) 	 if 	$mzml_index_valid and not 	$mzml_noindex_valid;
}	



__PACKAGE__->meta->make_immutable;